from collections import Counter


def text_processor(text):
    """文本处理工具"""
    print("文本分析报告:")
    print("=" * 40)
    print(f"原始文本: {text}")
    print(f"文本长度: {len(text)} 字符")
    print(f"单词数量: {len(text.split())}")
    # . 1 ！：2
    print(f"句子数量: {text.count('.') + text.count('!') + text.count('?')}")
    print(f"大写字母: {sum(1 for c in text if c.isupper())}")
    print(f"小写字母: {sum(1 for c in text if c.islower())}")
    print(f"数字数量: {sum(1 for c in text if c.isdigit())}")
    print(f"空格数量: {text.count(' ')}")

    # 最常用的5个字符

    char_count = Counter(text.replace(' ', ''))
    print(f"最常用字符: {char_count.most_common(5)}")

sample_text = "Hello World! This is a sample text. It contains 123 numbers and some punctuation!"
text_processor(sample_text)


def password_strength_checker(password):
    """密码强度检查器"""
    strength = 0
    feedback = []

    # 长度检查
    if len(password) >= 8:
        strength += 1
    else:
        feedback.append("密码至少8位")

    # 大写字母检查
    if any(c.isupper() for c in password):
        strength += 1
    else:
        feedback.append("包含大写字母")

    # 小写字母检查
    if any(c.islower() for c in password):
        strength += 1
    else:
        feedback.append("包含小写字母")

    # 数字检查
    if any(c.isdigit() for c in password):
        strength += 1
    else:
        feedback.append("包含数字")

    # 特殊字符检查
    special_chars = "!@#$%^&*()_+-=[]{}|;:,.<>?"
    if any(c in special_chars for c in password):
        strength += 1
    else:
        feedback.append("包含特殊字符")

    # 强度评级
    if strength == 5:
        rating = "非常强"
    elif strength >= 3:
        rating = "中等"
    else:
        rating = "弱"

    return {
        'strength': strength,
        'rating': rating,
        'feedback': feedback,
        'length': len(password)
    }


# 测试密码
passwords = ["abc", "password", "Password123", "StrongP@ssw0rd!"]

print("密码强度检查:")
for pwd in passwords:
    result = password_strength_checker(pwd)
    print(f"密码: {pwd:15} -> 强度: {result['strength']}/5 ({result['rating']})")
    if result['feedback']:
        print(f"  改进建议: {', '.join(result['feedback'])}")